﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Web.UI.Design;
using System.IO;
using System.Text.RegularExpressions;
using System.Reflection;
using System.Web.Services;
using System.ComponentModel.Design;
namespace AjaxSnippets.Design
{
    public class ConfigureSnippetCallbackWizard : WizardForm
    {
        private SnippetCallbackDesigner _SnippetCallbackDesigner;

        public string SelectedWebServiceVirtualPath { get; set; }
        private List<MethodInfo> _WebMethods;

        public List<MethodInfo> WebMethods
        {
            get { return _WebMethods; }
            set { _WebMethods = value; }
        }
        private MethodInfo _SelectedWebMethod;

        public MethodInfo SelectedWebMethod
        {
            get { return _SelectedWebMethod; }
            set { _SelectedWebMethod = value; }
        }
        public SnippetCallback SnippetCallback 
        {
            get
            {
                return (SnippetCallback)_SnippetCallbackDesigner.Component;
            }
        }

        private Dictionary<string, string> _ParameterMapping = new Dictionary<string,string>();

        public Dictionary<string, string> ParameterMapping
        {
            get { return _ParameterMapping; }
            set { _ParameterMapping = value; }
        }

        public ConfigureSnippetCallbackWizard(SnippetCallbackDesigner snippetCallbackDesigner, IServiceProvider serviceProvider) : base(serviceProvider)
        {
            _SnippetCallbackDesigner = snippetCallbackDesigner;



        }

        public override IEnumerable<WizardStep> GetWizardSteps()
        {
            List<WizardStep> steps = new List<WizardStep>();
            steps.Add(new ChooseWebMethodWizardStep(this));
            steps.Add(new MapParametersWizardStep(this));

            return steps;
        }
        protected override void Initialize()
        {
            base.Initialize();
          //  InitializeComponent();
        }

        protected override void OnFinish()
        {
            SnippetCallback.ParameterMapping.Clear();
            SnippetCallback.WebServiceMethodName = SelectedWebMethod.Name;
            SnippetCallback.WebServiceVirtualPath = SelectedWebServiceVirtualPath;

            foreach (string key in this.ParameterMapping.Keys)
            {
                CallbackParameterMapping mapping = new CallbackParameterMapping();
                mapping.ControlID = this.ParameterMapping[key];
                mapping.ArgumentName = key;
                SnippetCallback.ParameterMapping.Add(mapping);
            }


            base.OnFinish();
        }
    }
}
